package com.open.capacity.recuritment.service.impl;

import com.open.capacity.common.exception.service.ServiceException;
import com.open.capacity.common.model.SysUser;
import com.open.capacity.common.util.PageUtil;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.recuritment.dao.UnemployedDao;
import com.open.capacity.recuritment.service.IUnemployedService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.stream.Collectors;

@Service
public class UnemployedServiceImpl implements IUnemployedService {
    @Resource
    private UnemployedDao unemployedDao;

    @Override
    public PageResult<SysUser> findUnemployed(Map<String, Object> params) {

        try {
            int total = unemployedDao.count(params);
            List<SysUser> list = Collections.emptyList();
            List<SysUser> pList = Collections.emptyList();
            if (total > 0) {
                PageUtil.pageParamConver(params, true);
                list = unemployedDao.findUnemployed(params);

//                for (SysUser u:list) {
//                    pList.add(u);
//                }

//                List<Long> userIds = list.stream().map(SysUser::getId).collect(Collectors.toList());
//                List<SysRole> sysRoles = unemployedDao.findRolesByUserIds(userIds);
//
//                list.forEach(u -> {
//                    u.setRoles(sysRoles.stream().filter(r -> !ObjectUtils.notEqual(u.getId(), r.getUserId()))
//                            .collect(Collectors.toList()));
//                });
//                    pList.forEach(pp->{
//                        String position=pp.getPosition();
//                        pp.setPosition(position);
//                    });
                list.forEach(p -> {
                    Integer employed = p.getEmployed();
                    if (employed!=null&&(!employed.equals(""))){// 避免空指针异常
                        if (employed == 0) {
                            p.setEmployedStatus("待业中");
                        } else {
                            p.setEmployedStatus("已就业");
                        }
                    }
                });
            }
            return PageResult.<SysUser>builder().data(list).code(0).count((long) total).build();
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException(e);
        }
    }

}
